package org.paramita.tradestrategy;
import java.util.HashMap;

/** 
 * This class manages the creation and management of strategies 
 * @author pawandeep
 *
 */

//todo: Need to register strategies using a registerStrategy() method
//todo: Need to un-register strategies using a unRegisterStrategy() method
//todo: The actual software arbitrager would register and de-register strategies

public class StrategyManager {

	protected StrategyManager()
	{
		
	}
		
	private static StrategyManager _instance = null;
	private static HashMap<Integer,String> m_strategyMap;
	private StrategyConfig m_config;
	private String m_strategyClass;

	public static void setM_strategyMap(HashMap<Integer, String> map) {
		m_strategyMap = map;
	}

	/**
	 * @return
	 */
	public static StrategyManager getInstance()
	{
		if(null==_instance){
			_instance = new StrategyManager();
			m_strategyMap = new HashMap<Integer, String>();
			//todo: The actual software arbitrager would register and de-register strategies
			m_strategyMap.put(0,"org.paramita.tradestrategy.ArbitrageTradingStrategy");			
		}		
		return _instance;		
	}

	private String getStrategyClass(int strategyNum)
	{
		return(m_strategyMap.get(strategyNum));
	}


	public TradingStrategy createStrategy(StrategyConfig config) throws Exception
	{
	   	m_config=config;
	    int m_strategyNum = m_config.getStrategy();
	   	m_strategyClass = this.getStrategyClass(m_strategyNum);
	   	
	    TradingStrategy tradStrat = (TradingStrategy)Class.forName(m_strategyClass).newInstance(); 
	   	tradStrat.setConfig(config);
	   		   	
	   	
	   	return tradStrat;
		
	}

}
